const domain = 'https://hsry-dev-api.chenxingent.com'
export default {
	get(url, params) {
		return this.request(url, params, 'GET');
	},
	post(url, params) {
		return this.request(url, params, 'POST');
	},
	request(url, params, method) {
		url = domain + url
		return new Promise((resolve, reject) => {
			uni.request({
				url: url,
				data: params,
				method: method,
				header: {
					'content-type': 'application/json', //x-www-form-urlencoded
					'Authorization': 'Bearer ' + uni.getStorageSync('token')
				},
				success: (res) => {
					if (res.data.code === 9401) {
						uni.showToast({
							title: '登录失效',
							icon: 'none'
						})
						uni.setStorage({
							key: 'token',
							data: ''
						})
						uni.setStorage({
							key: 'userInfo',
							data: ''
						})
					} else {
						resolve(res.data);
					}
				},
				fail: (err) => {
					reject(err);
				}
			});
		});
	}
};